import 'package:flutter/material.dart';
import 'package:untitled/pages/applife_page.dart';
import 'package:untitled/pages/news_page.dart';
import 'package:untitled/pages/test_home_page1.dart';

import 'applife_page2.dart';

class TestHomePage2 extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _TestHomePage2State();
  }
}

class _TestHomePage2State extends State<TestHomePage2> {
  int _count = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('页面2')),
      body: Column(
        children: [
          Center(child: Text('页面主体 $_count')),

          SizedBox(height: 40),

          ElevatedButton(
            onPressed: () {
              Navigator.of(context).push(
                MaterialPageRoute(
                  builder: (BuildContext context) {
                    return TestHomePage1();
                  },
                ),
              );
            },
            child: Text("打开 首页"),
          ),

          SizedBox(height: 10),

          ElevatedButton(
            onPressed: () async {
              //等待结果
              dynamic res = await Navigator.of(context).push(
                MaterialPageRoute(
                  builder: (BuildContext context) {
                    return TestHomePage1(title: '测试 123');
                  },
                ),
              );

              print('页面关闭 $res');
            },
            child: Text("打开 首页 传参数  "),
          ),

          SizedBox(height: 40),

          OutlinedButton(
            onPressed: () {
              //第一步
              Navigator.of(context).pushNamed('/settings');
            },
            child: Text('命名路由 打开设置'),
          ),
          OutlinedButton(
            onPressed: () {
              int id = 3004;
              //第一步
              Navigator.of(context).pushNamed('/info', arguments: id);
            },
            child: Text('命名路由 打开详情'),
          ),

          SizedBox(height: 40),
          OutlinedButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (BuildContext context) {
                    return NewsPage();
                  },
                ),
              );
            },
            child: Text(' 打开  新闻页面'),
          ),
          SizedBox(height: 40),
          OutlinedButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (BuildContext context) {
                    return AppLifePage();
                  },
                ),
              );
            },
            child: Text(' 打开  生命周期'),
          ),
          OutlinedButton(
            onPressed: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                  builder: (BuildContext context) {
                    return AppLifePage2();
                  },
                ),
              );
            },
            child: Text(' 打开  生命周期'),
          ),
        ],
      ),
      floatingActionButton: FloatingActionButton(
        child: Icon(Icons.add),
        onPressed: () {
          _count++;
          setState(() {});
        },
      ),
    );
  }
}
